<?php

namespace App\Http\Requests;

use Illuminate\Validation\Rule;

class ProjectRequests extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'id' => 'numeric',
            'name' => [
                'required',
                Rule::unique('projects', 'name')->ignore($this->id)->where(function ($query) {
                    $query->where('name', $this->name)->where("level", $this->level);
                })
            ],
            'repo_url' => 'required',
            'level' => 'required',
            'status' => 'required',
        ];
    }

    public function messages()
    {
        return [
            'numeric' => trans('validation.numeric'),
            'required' => trans('validation.required'),
            'unique' => trans('validation.unique'),
        ];
    }

    public function attributes()
    {
        return [
            'id' => trans('labels.id'),
            'name' => trans('labels.project.name'),
            'repo_url' => trans('labels.project.repo_url'),
            "level" => trans('labels.project.level'),
            "status" => trans("labels.project.status")
        ];
    }
}
